<template>
  <div>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in swiperImg" :key="item.id">
        <img
          :src="'http://liufusong.top:8080' + item.imgSrc"
          alt=""
          class="vant-img-swipe"
        />
      </van-swipe-item>
    </van-swipe>

    <!-- 顶部输入框 -->
    <div class="top-search-title">
      <!-- 城市按钮 -->
      <span class="city-btn" @click="cityGoto"
        >{{ cityName }}<van-icon name="play" class="vant-icon-plat"
      /></span>
      <van-search
        v-model="value"
        placeholder="请输入小区地址"
        class="input-serch"
      />
    </div>
    <!-- 地图标记 -->
    <van-icon name="location-o" class="Map-icon" @click="$router.push('/map')"/>

    <div class="navbox">
      <div class="sonBox">
        <img
          src=""
          alt=""
          class="icon-son"
          @click="gotoActive('整租')"
        />
        <span class="text">整租</span>
      </div>
      <div class="sonBox">
        <img
          src=""
          alt=""
          class="icon-son"
          @click="gotoActive('合租')"
        />
        <span class="text">合租</span>
      </div>
      <div class="sonBox">
        <img
          src=""
          alt=""
          class="icon-son"
          @click="gotoActive('地图找房')"
        />
        <span class="text">地图找房</span>
      </div>
      <div class="sonBox">
        <img
          src=""
          alt=""
          class="icon-son"
          @click="gotoActive('去出租')"
        />
        <span class="text">去出租</span>
      </div>
    </div>

    <div class="navlist">
      <div class="listtop">
        <span class="title">租房小组</span>
        <span class="morelist">更多</span>
      </div>
      <!-- http://liufusong.top:8080/img/groups/4.png -->
      <!-- :icon="" -->
      <van-grid :column-num="2" :gutter="10" direction="horizontal">
        <van-grid-item
          :text="item.title"
          class="listcontent"
          v-for="item in hos"
          :key="item.id"
        >
          <van-image
            :src="'http://liufusong.top:8080' + item.imgSrc"
            class="van-img-my"
          />
          <div class="van-text-my">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </van-grid-item>
      </van-grid>
    </div>
  </div>
</template>

<script>
import { swiper, listcontent } from '@/api/Interface'
import { getToken } from '@/utils/storage'

export default {
  data() {
    return {
      value: '',
      swiperImg: [],
      cityId: 'AREA|88cff55c-aaa4-e2e0',
      cityName: '上海',
      hos: [],
    }
  },
  methods: {
    cityGoto() {
      this.$router.push('/city')
    },
    gotoActive(msg) {
      if (msg === '整租' || msg === '合租') {
        this.$router.push('/home/list')
      } else if (msg === '地图找房') {
        this.$router.push('/map')
      } else if (msg === '去出租') {
        getToken() ? this.$router.push('/rent/add') : this.$router.push('/login')
      }
    },
  },

  async created() {
    JSON.parse(localStorage.getItem('labelCity')) &&
      (this.cityId = JSON.parse(localStorage.getItem('labelCity')).value)
    JSON.parse(localStorage.getItem('labelCity')) &&
      (this.cityName = JSON.parse(localStorage.getItem('labelCity')).label)
    const res = await swiper()
    this.swiperImg = res.body

    const listres = await listcontent(this.cityId)
    console.log(listres)
    this.hos = listres.body
  },
}
</script>

<style scoped lang="less">
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
  height: 211px;
}
.top-search-title {
  position: absolute;
  top: 25px;
  left: 20px;
  width: 100%;
  height: 34px;
  padding: 0 5px;
  // background-color: rgba(0, 0, 0, 0);
  background-color: #fff;
  border-radius: 5px 5px;
  overflow: hidden;
  display: flex;
  align-content: center;
  width: 80%;
}
.input-serch {
  width: 188px;
  height: 34px;
  background-color: #fff !important;
  color: #9c9fa1;
}
.vant-img-swipe {
  width: 100%;
}
.city-btn {
  height: 20px;
  font-size: 14px;
  line-height: 20px;
  padding-right: 10px;
  background-color: #fff;
  // border-radius: 3px  0 0 3px;
  border-right: 1px solid #e5e5e5;
  margin-top: 8px;
}
.vant-icon-plat {
  transform: rotate(90deg);
  font-size: 14px;
}
.Map-icon {
  position: absolute;
  top: 30px;
  right: 10px;
  font-size: 20px;
  color: #fff;
  width: 25px;
  height: 25px;
}
.navbox {
  display: flex;
  align-content: center;
  justify-content: space-between;
  padding: 10px 0px 0 0px;
  height: 112px;
  .sonBox {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 25%;
    .icon-son {
      width: 60px;
      height: 60px;
    }
    .text {
      font-size: 14px;
      margin: 10px 0;
      display: block;
      width: 100%;
      text-align: center;
    }
  }
}
.navlist {
  height: 207.5px;
  background-color: #f6f5f6;
  // padding: 0 10px;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0);
  .listtop {
    margin: 15px 0 15px 5px;
    display: flex;
    padding: 0 10px;
    justify-content: space-between;
    .title {
      font-weight: 700;
      font-size: 15px;
    }
    .morelist {
      font-size: 14px;
      color: #787d82;
    }
  }
  // .listcontent {
  //   width: 50px !important;
  //   height: 70px !important;
  // }
  .van-img-my {
    width: 30px;
  }
  .van-text-my {
    font-size: 14px;
    margin-left: 10px;
    p {
      margin: 0;
    }
  }
}
</style>
